package com.ming.core.util;

import java.util.concurrent.TimeUnit;

public class MyTask implements Runnable{

	private boolean needSet;
	private ThreadLocal<Person> aPerson;
	
    
    MyTask (boolean needSet,ThreadLocal<Person> aPerson) {
        this.needSet = needSet;
        this.aPerson =  aPerson;
    }
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + " Start......");
        // 休眠3s
        try {TimeUnit.SECONDS.sleep(3);} catch (InterruptedException e) {}
        
        if (needSet)
            // 向ThreadLocal设置一个值
            aPerson.set(new Person(Thread.currentThread().getName(), 11));
            
        System.out.println("Thread Name: " + Thread.currentThread().getName()
                + "This thread's ThreadLocal: " + aPerson.get().toString());
    }
}
